#ifndef __EFFECT_MANAGER__
#define __EFFECT_MANAGER__

#include "Ogre.h"

class EffectBase;

using namespace Ogre;


class EffectManager
{
public:

	~EffectManager();

	enum EffectType
	{
		EFT_STORMLIGHTNING,
	};

	enum VanishFunctionType
	{
		VFT_LINEAR,
		VFT_PARA,
		VFT_TRIANGLUAR,
	};


	SceneManager * m_pSceneMgr;
	Camera * m_pCamera;

	static EffectManager* getInstance();

	void createEffect(Ogre::UTFString name, EffectType type);

	void setParNeeded(SceneManager *, Camera *);

	void registerEffectInstance(UTFString name, EffectBase* instance);

	void update(Ogre::Real timeSinceLast);
	void eventClick(int _xx, int _yy);
	void eventMouseMove(int _x, int _y, int _xRel, int _yRel, bool isButtonDown);
	void eventMouseRelease(int _xx, int _yy);
	void stateMouseDown(int _x, int _y, int _xRel, int _yRel, bool isButtonDown);

	EffectBase * getEffect(Ogre::UTFString name);

	/**Does NOT hide vanished object automatically. 
	Will return to be visible with full transparency 
	when vanishing process finished.
	So it needs setVisable(false) manually if it needs hiding*/
	void registerVanishPass(Ogre::Pass *pass, Ogre::Real timeLeft, VanishFunctionType type,Ogre::Real* param);

	
	void triggerFullScreenMaskVanish(Vector3 rgbColor,Ogre::Real timeLeft, 
		VanishFunctionType type,
		Ogre::Real *param);

protected:

	static EffectManager * selfSingleton;

	typedef std::map<UTFString, EffectBase *> EffectMap;
	EffectMap mEffectMap;

	typedef struct _vanishElement
	{
		Ogre::Real timePassed;
		Ogre::Real timeLeft;
		Ogre::Pass * pass;
		VanishFunctionType vft;
		Ogre::Real vft_para[10];
		bool needErase;
	public:
		_vanishElement(){};
		~_vanishElement(){};
	}VanishElement;
	typedef std::vector<VanishElement *> VanishElementVector;
	VanishElementVector mVanishingPass;

	void _vanishProcess(VanishElement *, Ogre::Real timeSinceLast);

	Ogre::Real mFullScreenMaskAlpha;
	Ogre::ManualObject *m_pFullScreenManualObject;
	Ogre::Pass * mFullScreenMaskPass;

	Ogre::Pass* _createFullScreenMask(Vector3 rgbColor);

private:

	EffectManager();
};



#endif